package configs

import (
	"encoding/json"
	"io/ioutil"
	"log"
)

type AppConfig struct {
	HttpPort  int    `json:"httpPort"`
	InfluxUrl string `json:"influxUrl"`
	Bucket    string `json:"bucket"`
	Org       string `json:"org"`
	Token     string `json:"token"`
	RpcPort   int    `json:"rpcPort"`
	ManageUrl string `json:"manageUrl"`
	SendUrl   string `json:"sendUrl"`
}

var ac = AppConfig{HttpPort: 8080}

func LoadConfig(configFile string) {
	bytes, err := ioutil.ReadFile(configFile)
	if err != nil {
		log.Fatalf("fail to read config file: %s, error: %v", configFile, err)
	}

	if err = json.Unmarshal(bytes, &ac); err != nil {
		log.Fatalf("config file decode error: %v", err)
	}

}

func GetConfig() AppConfig {
	return ac
}
